import { getAllPlatform } from '@hs-server/api'
import { getPublishAtlasList } from '@/api/biomedical'

export function getPublishPlatformMap(
  from:
    | '生物医药专区'
    | '新能源专区'
    | '产业预警通'
    | '汽车专区'
    | '新材料专区'
    | '未来产业专区'
    | '数字经济专区'
    | '高端装备专区'
    | '农业专区'
    | '食品专区'
    | '传统制造业专区'
    | '数字创意专区'
) {
  return getAllPlatform({ use_for: 'industry' }).then((res) => {
    const parentItem = res.find((item: { label: string }) => Object.is(item.label, '产业预警通'))

    let platform_id__in
    if (Object.is(from, '产业预警通')) {
      platform_id__in = parentItem.value
    } else if (Object.is(from, '生物医药专区')) {
      platform_id__in = parentItem.children.find((item: { label: string | string[] }) => item.label.includes('生物医药专区'))?.value
    } else if (Object.is(from, '新能源专区')) {
      platform_id__in = parentItem.children.find((item: { label: string | string[] }) => item.label.includes('新能源专区'))?.value
    } else if (Object.is(from, '汽车专区')) {
      platform_id__in = parentItem.children.find((item: { label: string | string[] }) => item.label.includes('汽车专区'))?.value
    } else if (Object.is(from, '新材料专区')) {
      platform_id__in = parentItem.children.find((item: { label: string | string[] }) => item.label.includes('新材料专区'))?.value
    } else if (Object.is(from, '未来产业专区')) {
      platform_id__in = parentItem.children.find((item: { label: string | string[] }) => item.label.includes('未来产业专区'))?.value
    } else if (Object.is(from, '数字经济专区')) {
      platform_id__in = parentItem.children.find((item: { label: string | string[] }) => item.label.includes('数字经济专区'))?.value
    } else if (Object.is(from, '高端装备专区')) {
      platform_id__in = parentItem.children.find((item: { label: string | string[] }) => item.label.includes('高端装备专区'))?.value
    } else if (Object.is(from, '农业专区')) {
      platform_id__in = parentItem.children.find((item: { label: string | string[] }) => item.label.includes('农业专区'))?.value
    } else if (Object.is(from, '食品专区')) {
      platform_id__in = parentItem.children.find((item: { label: string | string[] }) => item.label.includes('食品专区'))?.value
    } else if (Object.is(from, '传统制造业专区')) {
      platform_id__in = parentItem.children.find((item: { label: string | string[] }) => item.label.includes('传统制造业专区'))?.value
    } else if (Object.is(from, '数字创意专区')) {
      platform_id__in = parentItem.children.find((item: { label: string | string[] }) => item.label.includes('数字创意专区'))?.value
    }
    return getPublishAtlasList({ platform_id__in }).then((res) => {
      const unique = res.items.map((item: { name: any }) => ({
        ...item,
        node_name: item.name
      }))
      return unique
    })
  })
}
